package com.qf.filter;


import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.net.ServerSocket;

/**
 * @author LiXuekai on 2022/5/22
 */
@WebFilter("/*")
public class EncodingFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        //处理请求对象字符集编码
        servletRequest.setCharacterEncoding("utf-8");
        //处理响应字符集编码
        servletRequest.setCharacterEncoding("utf-8");
        //处理响应头编码
        servletResponse.setContentType("text/html; charset=UTF-8");
        //放行请求， 到下一个过滤器
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {

    }
}